package com.wdz.kafka;


import com.wdz.kafka.entity.EmailEntity;
import com.wdz.tofs.tofs_menu.entity.TofsMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutionException;

/**
 * Kafka生产者
 */
@Component
public class Product {

    //注入KafkaTemplate对象
    @Autowired
    private KafkaTemplate<Object, Object> kafkaTemplate;

    public void sendMsg(String topic,String key,String msg){
        //这里发送的消息可以直接使用Object
        //因为我们在配置文件中已经制定序列化的类
        kafkaTemplate.send(topic,key,msg);
    }

    public void sendEmail(String topic,String key, EmailEntity emailEntity) throws ExecutionException, InterruptedException {
        kafkaTemplate.send(topic,key,emailEntity);
    }
}
